$(function() {
	BTAvgP();
})

function BTAvgP() {
	jQuery("table[width=455]>tbody").each(function() {
		DefTotal = 0; DefLosses = 0; AttTotal = 0; AttLosses = 0;
		var Dessies = $(this).find("td:contains('Destroyers')"); 
		if (Dessies!=null) { 
			DefTotal  += 73*getIntFromAvgp(Dessies.next().next().next().text()); DefLosses += 73*getIntFromAvgp(Dessies.next().next().next().next().text());
			AttTotal  += 73*getIntFromAvgp(Dessies.next().next().next().next().next().text()); AttLosses += 73*getIntFromAvgp(Dessies.next().next().next().next().next().next().text());
		}
                var Cruisers = $(this).find("td:contains('Cruisers')");
                if (Cruisers!=null) {
                        DefTotal  += 475*getIntFromAvgp(Cruisers.next().next().next().text()); DefLosses += 475*getIntFromAvgp(Cruisers.next().next().next().next().text());
                        AttTotal  += 475*getIntFromAvgp(Cruisers.next().next().next().next().next().text()); AttLosses += 475*getIntFromAvgp(Cruisers.next().next().next().next().next().next().text());
                }
                var Scouts = $(this).find("td:contains('Scouts')");
                if (Scouts!=null) {
                        DefTotal  += 8*getIntFromAvgp(Scouts.next().next().next().text()); DefLosses += 8*getIntFromAvgp(Scouts.next().next().next().next().text());
                        AttTotal  += 8*getIntFromAvgp(Scouts.next().next().next().next().next().text()); AttLosses += 8*getIntFromAvgp(Scouts.next().next().next().next().next().next().text());
                }
                var Bombers = $(this).find("td:contains('Bombers')");
                if (Bombers!=null) {
                        DefTotal  += 40*getIntFromAvgp(Bombers.next().next().next().text()); DefLosses += 40*getIntFromAvgp(Bombers.next().next().next().next().text());
                        AttTotal  += 40*getIntFromAvgp(Bombers.next().next().next().next().next().text()); AttLosses += 40*getIntFromAvgp(Bombers.next().next().next().next().next().next().text());
                }
		$(this).append('<tr><td colspan="7"><font face="verdana,arial" color="#777777" size="1">DEF:'+ getAvgpFromInt(DefTotal) +' (lost: '+getAvgpFromInt(DefLosses)+' - '+(Math.round((1000*DefLosses)/(Math.max(1,DefTotal)))/10)+'%). ATT:'+ getAvgpFromInt(AttTotal) +' (lost:'+getAvgpFromInt(AttLosses)+' - '+(Math.round((1000*AttLosses)/(Math.max(1,AttTotal)))/10)+'%).</font></td></tr>');
	});
}